package com.rrd.hive.udf;

import org.apache.hadoop.hive.ql.exec.UDF;
import org.apache.hadoop.io.Text;

import java.util.ArrayList;

/**
 * @author songxin
 */
public class AmountRangeUDF extends UDF{

    public Text evaluate(Double amount) {
        String range = "";
        if (amount == null) {
            return null;
        } else if (amount >= 0 && amount < 500) {
            range = "[0,500)";
        } else if (amount >= 500 && amount < 1000) {
            range = "[500,1000)";
        } else if (amount >= 1000 && amount < 2000) {
            range = "[1000,2000)";
        } else if (amount >= 2000 && amount < 3000) {
            range = "[2000,3000)";
        } else if (amount >= 3000 && amount < 4000) {
            range = "[3000,4000)";
        } else if (amount >= 4000 && amount < 5000) {
            range = "[4000,5000)";
        } else if (amount >= 5000 && amount < 6000) {
            range = "[5000,6000)";
        } else if (amount >= 6000 && amount < 7000) {
            range = "[6000,7000)";
        } else if (amount >= 8000 && amount < 9000) {
            range = "[8000,9000)";
        } else if (amount >= 9000 && amount < 10000) {
            range = "[9000,10000)";
        } else if (amount >= 10000) {
            range = "[10000,+)";
        } else {
            return null;
        }
        Text result = new Text();
        result.set(range);
        return result;
    }
}
